<?php

//登录日志写入数据库

namespace listen;

use app\admin\model\Admin\Log as LogModel;

class LoginLog
{

    public function handle($user)
    {

        $ip = request()->ip();
        $data['ip'] = $ip;
        $data['city'] = \utils\IpAddress::getIpInfo($ip);

        $data['application_name'] = app('http')->getName();
        $data['username'] = $user['username'];
        $data['creater_id'] = $user['user_id'];
        $data['creater_dept'] = $user['dept_id'];
        $data['url'] = request()->url(true);
        $data['useragent'] = request()->server('HTTP_USER_AGENT');
        $data['create_time'] = date('Y-m-d H:i:s');
        $data['type'] = 1;
        $data['status'] = 1;

        $loginfo = LogModel::create($data);
        if ($loginfo->id) {
            LogModel::update(['sort_id' => $loginfo->id, 'id' => $loginfo->id]);
        }
    }
}